#include<bits/stdc++.h>
using namespace std;
void solve()
{
	int n;
	scanf("%d",&n);
	vector<int> a(n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	vector<int> c(n, 0);
	int ma=INT_MIN;
	while(c[0] < 2)
	{
		vector<int> C(n);
		for(int i=1;i<n;i++)
		{
			int j=i-1;
			while(c[j]!=c[i]&&j>=0)
			{
				j--;
			}
			if(j==-1)
				C[i]=0;
			if(a[i]==a[j])
				C[i]=a[i];
			else
				C[i]=0;
		}
		int sum=0;
		for(int i=0;i<n;i++)
		{
			sum+=C[i];
		}
		if(sum>ma)
			ma=sum;
		c[c.size() - 1]++;
		for (int i = c.size() - 1; i > 0; i--)
		{
			if (c[i] == 2)
			{
				c[i] = 0;
				c[i - 1]++;
			}
		}
	}
	printf("%d\n",ma);
}
int main()
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int T;
	scanf("%d",&T);
	while(T--)
	{
		solve();
	}
	return 0;
}